package com.hc.serviceimpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.entity.Environmentmv;
import com.hc.mapper.EnvironmentmvMapper;
import com.hc.service.IEnvironmentmvService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiuZhiHao
 * @since 2019-12-04
 */
@Service
@Slf4j
public class EnvironmentmvServiceImpl extends ServiceImpl<EnvironmentmvMapper, Environmentmv> implements IEnvironmentmvService {

    @Autowired
    private EnvironmentmvMapper environmentmvMapper;


    @Override
    public Map<String, List<Environmentmv>> selectEnvironmentmvday(String date) {
        //获得当天所有环境的数据集合
        List<Environmentmv> environmentmvs = environmentmvMapper.selectEnvironmentmvday(date);
        //按照天名字分组
        //获得培养箱的名称集合
        return environmentmvs.stream().collect(Collectors.groupingBy(Environmentmv::getEquipmentName));
    }


    @Override
    public Map<String, List<Environmentmv>> selectEnvironmentmvmonth(String equipmentName, String startTime, String endTime) {
            //调用mapper层接口,获得list结合
        List<Environmentmv> environmentmvs = environmentmvMapper.selectEnvironmentmvmonth(equipmentName, startTime, endTime);
        return environmentmvs.stream().collect(Collectors.groupingBy(r -> r.getInputTime().substring(0, 10)));
    }

}
